<template>
  <div class="point-list-wrap">
    <div class="chose-course-top">
      <div class="header-left">
        <span class="back-arrow" v-if="!isnew" @click="() => this.$router.push('/super-read')"></span>
        <span class="back-arrow" v-else @click="handleSelectLexicon"></span>
      </div>
      <div class="course-title">
        {{ package_name }}
        {{ +this.$route.query.type === 1 ? "·阅读理解" : "" }}
      </div>
      <div class="btn-group"></div>
    </div>
    <div class="list-wrap">
      <div class="list-content">
        <div
          class="list-item"
          @click="pointClick(list)"
          v-for="list in pointList"
          :key="list.id"
        >
          <div class="top-img">
            <template v-if="+list.write_count > 0">
              <img src="~assets/super-read/point-book.png" alt="" />
            </template>
            <template v-else>
              <img src="~assets/super-read/point-book-disabled.png" alt="" />
            </template>
          </div>
          <div class="list-title">
            {{ list.level_title }}
          </div>
          <span
            class="list-round"
            :class="{ 'round-hidden': +list.write_count === 0 || +list.course_type === 0 }"
            >round {{ list.write_count }}</span
          >
          <template v-if="+list.write_count > 0">
            <div class="list-complete">
              <img src="~assets/super-read/point-complete.png" alt="" /><span
                >已完成</span
              >
            </div>
          </template>
          <template v-else>
            <div class="list-nocomplete">
              未完成
            </div>
          </template>
        </div>
      </div>
    </div>
    <Timetips ref="timetips"></Timetips>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
import { fetchNewCurriculum,fetchCurriculum, isChecked } from "@/services/super-read";
import { SUCCESS_CODE } from "@/utils/const";
import Timetips from "@/components/Timetips";
const studyPrecheck = require("assets/super-read/study-precheck.png");
const wordCheck = require("assets/super-read/word-check.png");
export default {
  name: "pointList",
  components: {
    Timetips
   },
  data() {
    return {
      pointList: [],
      isnew:0,
      package_name:'',
      parent_id:0,
      detailPath: +this.$route.query.type === 6
          ? "/super-read/pushblank"
          : "/super-read/pushword",
      analysisPath: +this.$route.query.type === 6
          ? "/super-read/analysis-blank"
          : "/super-read/analysis",
    };
  },
  computed: {
    ...mapState({
      readCourseInfo: (state) => state.readCourseInfo,
      userInfo: (state) => state.userInfo,
    }),
  },
  watch: {},
  methods: {
    ...mapMutations(["setReadCurrent"]),
    initList() {
      //新版阅读
      if(this.$route.query.isnew){
        this.isnew = this.$route.query.isnew;
        this.parent_id = this.$route.query.parent_id;
		this.package_id = this.$route.query.id;
        this.package_name = this.$route.query.title;
        fetchNewCurriculum({
          package_id: this.$route.query.id
        }).then((res) => {
          if (res.code === SUCCESS_CODE) {
            this.pointList = res.data;
            //   console.log(this.pointList);
          }
        });
      }else {
        this.package_name = this.readCourseInfo.title;
        fetchCurriculum({
          curriculum_id: this.readCourseInfo.id,
          question_type: this.$route.query.type,
          type: 1,
        }).then((res) => {
          if (res.code === SUCCESS_CODE) {
            this.pointList = res.data;
            //   console.log(this.pointList);
          }
        });
      }
    },
    handleSelectLexicon () {
      this.$router.push({
        path: "/super-read/doubleminusindex",
        query: {package_id: this.$route.query.parent_id}
      })
    },
    pointClick(list) {
      const { readsplit } = this.userInfo;
      if (+list.write_count >=3 && +list.course_type === 1) {
        this.setReadCurrent(list);
		if(list.question_type == 6){
            this.analysisPath = '/super-read/analysis-blank';
            this.$route.query.type = 6
		}
        this.$router.push({
          path: this.analysisPath,
          query: {
            over: true,
            isnew:this.isnew,
            parent_id:this.parent_id,
            package_id:this.$route.query.id,
            title:this.$route.query.title
          }
        })
        return
      }
      if (+list.write_count > 0 || +list.is_split === 1 || +readsplit === 0) {
        if (+readsplit === 0) {
          // 跳转做题页面-点选生词
          console.log(readsplit);
          this.setReadCurrent(list);
          if(list.question_type == 6){
              this.detailPath = '/super-read/pushblank';
              this.$route.query.type = 6
          }
          this.$router.push({
            path: this.detailPath,
            query: {
              id: list.id,
              select_words: true,
              type: this.$route.query.type ,
              isnew:this.isnew,
              parent_id:this.parent_id,
              package_id:this.$route.query.id,
              title:this.$route.query.title
            },
          });
        }
        if (+readsplit === 1) {
			if(list.question_type == 6){
              this.detailPath = '/super-read/pushblank';
              this.$route.query.type = 6
			}
          //   跳转智能推词
          console.log(readsplit);
          this.setReadCurrent(list);
          this.$router.push({
            path: this.detailPath,
            query: {
              id: list.id,
              type: this.$route.query.type,
              isnew:this.isnew,
              parent_id:this.parent_id,
              package_id:this.$route.query.id,
              title:this.$route.query.title
            },
          });
        }
      } else {
        isChecked().then((res) => {
          if (res.code === SUCCESS_CODE) {
            if (res.data) {
              this.$yxpConfirm({
                msg: `
                <img width="223" src="${wordCheck}" alt=""/>
             <p>您需要先去做词汇量测试哦，根据您的英语水平，智能推送文章~</p>
                `,
                type: "alert",
                html: true,
                alertBtnText: "知道了",
              })
                .then(() => {})
                .catch(() => {});
            } else {
              this.$yxpConfirm({
                msg: `
                <img width="223" src="${studyPrecheck}" alt=""/>
             <p>根据您的单词学习情况智能生成单词列表，开始学习吧~</p>
                `,
                type: "alert",
                html: true,
                alertBtnText: "开始学习",
              })
                .then(() => {
                  this.$router.push({
                    path: "/super-read/beforeStudy",
                    query: { id: list.id, type: this.$route.query.type, modal: 1 ,isnew:this.isnew,package_id:this.package_id,parent_id:this.parent_id,title:this.title},
                  });
                  this.setReadCurrent(list);
                })
                .catch(() => {});
            }
          }
        });
      }
    },
  },
  created() {
    this.initList();
  },
  mounted() {},  
  beforeDestroy() {
    this.$refs.timetips.stopTimer();
    this.$refs.timetips.stopEndTimer();
  },
};
</script>
<style lang="less" scope>
/* @import url(); 引入公共css类 */
@import url("./index.less");
</style>
